package io.xxx.walle.assistant;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@Tag(name = "assistant")
@RestController
@RequestMapping("/assistant")
public class AssistantController {

    @Resource
    private AssistantService assistantService;

    /**
     * 创建小助手
     */
    @Operation(summary = "创建小助手", description = "创建小助手需要消耗一个Token")
    @ApiResponse(responseCode = "200", description = "已创建")
    @PostMapping("/create")
    public void create() throws IOException {
        assistantService.createRobot();
    }

    /**
     * 保存小助手信息
     */
    @PostMapping("/save")
    public void save(@RequestBody Assistant assistant) {
        assistantService.save(assistant);
    }

    /**
     * 失效小助手
     */
    @PostMapping("/invalid")
    public void invalid(@RequestBody Assistant assistant) {
        if (assistant.getId() == null) {
            throw new IllegalArgumentException("小助手ID不存在");
        }
        if (assistant.getToken().getId() == null) {
            throw new IllegalArgumentException("Token不存在");
        }
    }

    /**
     * 门店老板申请小助手
     */
    @GetMapping("/assign")
    public Assistant assign(
            @RequestParam Long storeId,
            @RequestParam Integer provinceId,
            @RequestParam Integer cityId
    ) {
        return assistantService.assign(storeId, provinceId, cityId);
    }
}
